home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-03-12 | 1.4 KB | 59 lines | [TEXT/CWIE] |
- //
- // CBoxMaker.cp
- //
- // class CBoxMaker
- // Constructs a single box and assigns colors to each face.
- // Note: The face attributes are members and will be released
- // in the destructor.
- //
- // by James Jennings
- // November 23, 1995
- //
- // November 26, 1995: Based on CObjectMaker
- //
-
- #include "CBoxMaker.h"
-
- // Note: I've put all of the initialization that allocates into Make()
- // rather than in the constructor. I'm not sure it matters.
-
- CBoxMaker::CBoxMaker( float inSize )
- { // init box data
- ::Q3Point3D_Set(&mData.origin, 0.0, 0.0, 0.0);
- ::Q3Vector3D_Set(&mData.orientation, 0.0, inSize, 0.0);
- ::Q3Vector3D_Set(&mData.majorAxis, 0.0, 0.0, inSize);
- ::Q3Vector3D_Set(&mData.minorAxis, inSize, 0.0, 0.0);
- mData.boxAttributeSet = nil;
-
- // set up the face attributes pointer
- for (int f=0; f<numFaces; f++)
- mFaces[f] = 0;
- mData.faceAttributeSet = mFaces;
- }
-
- CBoxMaker::~CBoxMaker()
- {
- for (int f=0; f<numFaces; f++)
- if (mFaces[f]) {
- ::Q3Object_Dispose(mFaces[f]);
- mFaces[f] = 0;
- }
- }
-
- void
- CBoxMaker::Make()
- {
- TQ3ColorRGB color;
-
- // init the face attributes
- for (int f = 0; f<numFaces; f++) {
- mFaces[f] = ::Q3AttributeSet_New();
- ThrowIfNil_(mFaces[f]);
- ::Q3ColorRGB_Set( &color, (((f+1)&1)?1.0:0.0), (((f+1)&2)?1.0:0.0), (((f+1)&4)?1.0:0.0) );
- ::Q3AttributeSet_Add(mFaces[f], kQ3AttributeTypeDiffuseColor, &color);
- }
- // create the box
- mObject = ::Q3Box_New(&mData);
- ThrowIfNil_(mObject);
- }
-